package com.sinosoft.msf.base.supplier.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import com.sinosoft.msf.base.supplier.dao.base.*;
import com.sinosoft.msf.base.supplier.pojo.RestEntity;
import com.sinosoft.msf.base.supplier.pojo.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author huangzhihao
 **/
@RestController
@RequestMapping("/sse")
public class TestController {

    @Autowired
    LcselfcustomerMapper lcselfcustomerMapper;
    @Autowired
    TCusDistributionAgentMapper tCusDistributionAgentMapper;
    @Autowired
    TCusDistributionTagtrailMapper tCusDistributionTagtrailMapper;
    @Autowired
    TCusDistributionActiontrailMapper tCusDistributionActiontrailMapper;
    @Autowired
    TCusDistributionAgentExtendMapper tCusDistributionAgentExtendMapper;
    @Autowired
    TCusMdLcselfLogsMapper tCusMdLcselfLogsMapper;
    @Autowired
    SSEMapper sseMapper;

    @GetMapping("/test")
    public RestEntity sseTest() {
        List<String> agentList = Arrays.asList("DJ035395",
                "DJ035603",
                "YB031798",
                "YB009113",
                "YB004808",
                "YB002953",
                "YB000112",
                "YB023237",
                "YB000197",
                "YB000138",
                "YB000150",
                "YB001099",
                "YB000092",
                "YB003377",
                "YB000028",
                "YB007892",
                "YB000033",
                "YB024502",
                "YB034205",
                "YB000094",
                "YB022795",
                "YB000448",
                "YB000130",
                "YB007888",
                "GX05001525",
                "GX05000830",
                "GX05000325",
                "GX05001147",
                "GX05002046",
                "GX05000004",
                "GX05001764",
                "GX05000020",
                "GX05000052",
                "GX05001672",
                "GX05001728",
                "GX05000017",
                "GX05001727",
                "GX05001317",
                "GX05001273",
                "GX05001682",
                "GX05001111",
                "GX05000059",
                "GX05000957",
                "GX05001316",
                "GX05001442",
                "GX05001465",
                "DJ033830",
                "DJ032760",
                "DJ030601",
                "YB025911",
                "YB035443",
                "YB038322",
                "YB000191",
                "YB023757",
                "YB027551",
                "YB029832",
                "YB000215",
                "YB038972",
                "YB003927",
                "GX14000042",
                "GX14001531",
                "GX14001222",
                "GX14001707",
                "GX14001210",
                "GX14001252",
                "GX14001449",
                "GX14001571",
                "GX14000055",
                "GX14001206",
                "GX14000904",
                "GX14000951",
                "DJ012023",
                "DJ028621",
                "YB010219",
                "YB033350",
                "YB002978",
                "YB029245",
                "YB010197",
                "YB037762",
                "YB019594",
                "YB034924",
                "YB004539",
                "DJ029302",
                "DJ032238",
                "DJ032596",
                "GX10002019",
                "GX10000926",
                "GX10001246",
                "GX10001095",
                "GX10000813",
                "GX10001275",
                "GX10001949",
                "GX10000256",
                "GX10000287",
                "GX10000842",
                "GX10002063",
                "GX10000511",
                "GX10000837",
                "GX10000638",
                "GX10000226",
                "GX10000249",
                "GX10001503",
                "GX10001168",
                "GX10001461",
                "GX10001452",
                "GX10000472",
                "GX10001140",
                "GX10001428",
                "GX10000275",
                "DJ032123",
                "YB031229",
                "YB009991",
                "YB017639",
                "YB003073",
                "YB026634",
                "YB030139",
                "YB033375",
                "DJ029793",
                "DJ034152",
                "YB038534",
                "DJ029104",
                "YB020257",
                "YB004616",
                "YB036127",
                "YB039650",
                "YB039668",
                "YB039674",
                "YB039667",
                "GX09000138",
                "GX09000039",
                "GX09000114",
                "GX09000190",
                "GX09000077",
                "GX09000254",
                "GX09000197",
                "GX09000201",
                "YB034210",
                "YB015865");
        List<TCusDistributionAgent> existList = sseMapper.queryMainExist();
        int count = 5000;
        for (String code : agentList) {
            List<TCusDistributionAgent> insertMainList = new ArrayList<>();
            List<TCusMdLcselfLogs> insertLogList = new ArrayList<>();
            List<TCusDistributionAgentExtend> insertExtendList = new ArrayList<>();
            for (TCusDistributionAgent agent : existList) {
                agent.setAgentcode(code);
                count++;
                String newSerialno = "sse" + count;
                agent.setSerialno(newSerialno);
                insertMainList.add(agent);
                TCusMdLcselfLogs log = new TCusMdLcselfLogs();
                log.setAgentcode(code);
                log.setAgentname(code);
                log.setMdserialno(newSerialno);
                log.setLcselfserialno("");
                log.setMakedate(new Date());
                log.setMaketime("17:01:09");
                log.setStatus("0");
                log.setMode("G");
                insertLogList.add(log);
                TCusDistributionAgentExtend extend = new TCusDistributionAgentExtend();
                extend.setSerialno(newSerialno);
                extend.setOccupation("8010101");
                extend.setEducational("20");
                extend.setMarriage("20");
                extend.setAssigndate(DateUtil.parseDate("2024-09-01"));
                extend.setAddress("北京市海淀区花园路182号");
                extend.setTotalpremium(BigDecimal.valueOf(105000.00));
                extend.setIssuebank("中国邮政储蓄银行");
                extend.setIssuenetwork("中国农业银行股份有限公司北京西三旗桥北支行");
                extend.setMakedate(new Date());
                extend.setSalary(BigDecimal.valueOf(18000));
                insertExtendList.add(extend);
            }
            tCusDistributionAgentMapper.insertList(insertMainList);
            tCusMdLcselfLogsMapper.insertList(insertLogList);
            tCusDistributionAgentExtendMapper.insertList(insertExtendList);
        }
        return RestEntity.success();
    }

    @GetMapping("/test2")
    public RestEntity sseTest2() {
        List<String> existList = sseMapper.queryauthorizeExist();
        TCusDistributionActiontrail actionTrail = sseMapper.queryActionTrail();
        List<TCusDistributionAgent> csutomerList = sseMapper.queryMainCsutomer();
        for (TCusDistributionAgent agent : csutomerList) {
            String serialno = agent.getSerialno();
            Lcselfcustomer lcselfcustomer = new Lcselfcustomer();
            BeanUtil.copyProperties(agent, lcselfcustomer, true);
            lcselfcustomer.setAgentcode(agent.getAgentcode());
            lcselfcustomer.setUserid(serialno);
            lcselfcustomer.setDetailaddress("03e9ba352424b9e383c3dac2b1490882ca42a5a9088877f19c7f2cfec366f60149db8262c82b99f896303209eb057227");
            lcselfcustomer.setOccupation("8010101");
            lcselfcustomer.setSalary("100000");
            lcselfcustomer.setMarriage("20");
            lcselfcustomer.setEducational("10");
            lcselfcustomer.setChannel("4");
            lcselfcustomer.setStandbyflag11("Y");
            lcselfcustomer.setMakedate(new Date());
            lcselfcustomer.setMaketime("14:26:20");
            lcselfcustomer.setModifydate(new Date());
            lcselfcustomer.setModifytime("14:26:20");
            lcselfcustomerMapper.insert(lcselfcustomer);
            sseMapper.updateLogs(serialno, serialno);
            sseMapper.updateMain(serialno);
            TCusDistributionTagtrail tagtrail = new TCusDistributionTagtrail();
            tagtrail.setMdserialno(serialno);
            tagtrail.setLcselfserialno(serialno);
            tagtrail.setActiontype("authorize");
            tagtrail.setActioncontent("Y");
            tagtrail.setMaketime(new Date());
            tCusDistributionTagtrailMapper.insert(tagtrail);
            TCusDistributionActiontrail actionTrailInsert = new TCusDistributionActiontrail();
            BeanUtil.copyProperties(agent, actionTrailInsert, true);
            actionTrailInsert.setMdserialno(serialno);
            actionTrailInsert.setLcselfserialno(serialno);
            actionTrailInsert.setActiontype("authorize-jhs");
            actionTrailInsert.setActionid("B002_20240801142620_43c074be-5379-49f3-a0ef-0eed00cab5e7");
            actionTrailInsert.setObj1("2024-09-20 14:26:20");
            actionTrailInsert.setObj2("大家百岁人生（畅享版）养老年金保险");
            actionTrailInsert.setObj3("13811090934");
            actionTrailInsert.setMaketime(new Date());
            tCusDistributionActiontrailMapper.insert(actionTrailInsert);
        }


        return RestEntity.success();
    }

}